#! /bin/bash
# author: 我的代码温柔如风

logfile=check.log
if [ -f ${logfile} ]; then
  rm -f ${logfile}
fi

echo "环境检查中...\n"

# Docker
echo "=================================================="
echo "Docker"
echo "=================================================="
docker version
if [ $? -eq 0 ]; then
  echo "Docker 环境已安装～\n"
else
  echo "未检测到 Docker 环境!!!\n"
  echo "需要安装 Docker 环境,安装指导参见 https://docs.docker.com/get-docker/" >> ${logfile}
fi

# Docker Compose
echo "=================================================="
echo "Docker Compose"
echo "=================================================="
docker-compose version
if [ $? -eq 0 ]; then
  echo "Docker Compose 环境已安装～\n"
else
  echo "未检测到 Docker Compose 环境!!!\n"
  echo "需要安装 Docker Compose 环境,安装指导参见 https://docs.docker.com/compose/install/" >> ${logfile}
fi

# Kubernetes
echo "=================================================="
echo "Kubernetes"
echo "=================================================="
kubectl version
if [ $? -eq 0 ]; then
  echo "Kubernetes 环境已安装～\n"
else
  echo "未检测到 Kubernetes 环境!!!\n"
  echo "需要安装 Kubernetes 环境,安装指导参见 https://kubernetes.io/zh/docs/tasks/tools/install-kubectl/" >> ${logfile}
fi

# Helm
echo "=================================================="
echo "Helm"
echo "=================================================="
helm version
if [ $? -eq 0 ]; then
  echo "Helm 环境已安装～\n"
else
  echo "未检测到 Helm 环境!!!\n"
  echo "需要安装 Helm 环境,安装指导参见 https://helm.sh/docs/intro/install/" >> ${logfile}
fi

echo "环境检查完毕."
